package cn.i96688.scanclient.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import cn.i96688.scanclient.bean.Status;

public class DebugData {
	private static boolean clientdebug=false;
	private static String merId="12345678";
	private static String merName="惠兰辰星";
	private static String deviceName="1号收银机";
	static {
		clientdebug="Y".equalsIgnoreCase(ConfParams.getValueByKey("clientdebug"));
	}
	public static boolean isDebug() {
		return clientdebug;
	}
	public static String generateData(String url, String params) {
		String msg="";
		if(url.endsWith(Constants.URI_MER_LOGIN)) {
			JSONObject js=Status.suc("登录成功");
			js.put("merId", merId);
			js.put("merName", merName);
			js.put("deviceCode", PayUtil.getLocalMAC());
			msg=js.toJSONString();
		}else if(url.endsWith(Constants.URI_MER_GET)) {
			JSONObject merInf=new JSONObject();
			merInf.put("merStatus", "1");
			merInf.put("merId", merId);
			merInf.put("merName", merName);
			merInf.put("deviceCode", PayUtil.getLocalMAC());//设备号mac
			merInf.put("deviceName", deviceName);//设备名称
			msg=merInf.toJSONString();
		}else if(url.endsWith(Constants.URI_ORDER_QUERY)) {
			JSONObject order=Status.suc("登录成功");
			order.put("payableAmount", getAmount());
			order.put("exchangeTime", getExchangeTime());
			order.put("orderStatus", Constants.ORDER_SUCCESS);
			msg=order.toJSONString();
		}else if(url.endsWith(Constants.URI_ORDER_LIST)) {
			JSONObject respMsg=Status.suc("登录成功");
			JSONArray orderList=new JSONArray();
			for(int i=0;i<5;i++) {
				JSONObject order=new JSONObject();
				order.put("orderNo", PayUtil.getOrderNoTest());
				order.put("payableAmount", getAmount());
				order.put("exchangeTime", getExchangeTime());
				order.put("deviceName", deviceName);//设备名称
				order.put("orderStatus", Constants.ORDER_SUCCESS);
				orderList.add(order);
			}
			respMsg.put(Status.DATA, orderList);
			msg=respMsg.toJSONString();
		}else if(url.endsWith(Constants.URI_PAY)) {
			JSONObject order=Status.suc("登录成功");
			order.put("orderNo", PayUtil.getOrderNoTest());
			order.put("exchangeTime", getExchangeTime());
			order.put("orderStatus", "1");
			msg=order.toJSONString();
			try {
				Thread.sleep(20);
			} catch (Exception e) {
			}
		}
		return msg;
	}
	static int getAmount() {
		return new Random().nextInt(50)+50;
	}
	static String getExchangeTime() {
		return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
	}
}
